/*
 * @Author: zgl 2191723570@qq.com
 * @Date: 2024-01-13 23:45:00
 * @LastEditors: zgl 2191723570@qq.com
 * @LastEditTime: 2024-01-13 23:53:13
 * @FilePath: /client2/assets/Script/sync/utils/TaskUtils.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
export default class TaskUtils {
    // static getTask(fn: Function, ctx: Object, ...arg: any) {
    //     return (next: Function) => {
    //         arg.push(next);
    //         arg = arg.filter(fn => fn != undefined);
    //         fn.call(ctx, ...arg)
    //     }
    // }
    // static line(task: Function[], onOneEnd?: Function) {
    //     let fn
    //     for (let i = 0; i < task.length - 1; i++) {
    //         let fn = task[i];
    //         let nextFn = task[i + 1];
    //         fn(nextFn);
    //     }
    // }


    static sync(task: Function[], complete: Function, ctx: unknown) {
        let completeNum = 0;
        let checkIfComplete = () => {
            completeNum++;
            if (task.length == completeNum) {
                complete.call(ctx);
            }

        }
        for (const taskF of task) {
            taskF.call(ctx, checkIfComplete)
        }
    }
}
